package com.etc.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.etc.dao.UserMapper;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.utils.EnDecryptUtil;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User checkUser(String uno, String upwd) {
		User user = userMapper.findUserByUno(uno);
		if (user != null) {
			if (upwd.length() != 40) {
				upwd = EnDecryptUtil.SHA1(upwd);
			}
			if (upwd.equals(user.getUpwd())) {
				return user;
			}
		}
		return null;
	}

	@Override
	public Boolean validateUno(String uno) {
		User user = userMapper.findUserByUno(uno);
		if (user != null) {
			return true;
		}

		return false;
	}

	@Override
	public Boolean addUser(User user) {
		int i = userMapper.insert(user);
		if (i > 0) {
			return true;
		}
		return false;
	}

	@Override
	public int updateUserInfoByUid(User user) {
		return userMapper.updateByPrimaryKeySelective(user);
	}

}
